//
//  MAddDeviceViewController.m
//  Mask
//
//  Created by 郭子一 on 2020/10/2.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MAddDeviceViewController.h"
#import "MAddDeviceCell.h"
@interface MAddDeviceViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MAddDeviceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.showNavView = YES;
    self.navTitleLab.text = @"添加设备";
    [self makeUI];
}

- (void)makeUI
{
    UIImageView *img = [[UIImageView alloc] init];
    img.backgroundColor = UIColor.cyanColor;
    [self.view addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(32);
        make.right.offset(-32);
        make.top.equalTo(self.navTitleLab.mas_bottom).offset(44);
        make.height.mas_equalTo(kGScreenWidth - 64);
    }];
    
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [addBtn addTarget:self action:@selector(addBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.top.equalTo(img.mas_bottom).offset(29);
        make.height.mas_equalTo(45);
    }];
    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,kGScreenWidth - 30,45);
    gl.startPoint = CGPointMake(0.05, 0.1);
    gl.endPoint = CGPointMake(1, 0.5);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:1/255.0 green:145/255.0 blue:254/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:195/255.0 blue:254/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    addBtn.layer.cornerRadius = 22.5;
    addBtn.layer.masksToBounds = YES;
    [addBtn.layer addSublayer:gl];
    [addBtn setTitle:@"连接设备" forState:UIControlStateNormal];
    [addBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [addBtn.titleLabel setFont:JSS_FONT_5];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kGScreenWidth, kGScreenHeight) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView registerClass:[MAddDeviceCell class] forCellReuseIdentifier:@"MAddDeviceCell"];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(addBtn.mas_bottom).offset(19);
        make.height.offset(165);
    }];
    
    UIButton *exploreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [exploreBtn setTitle:@"去探索 >>" forState:UIControlStateNormal];
    [exploreBtn setTitleColor:RGB_VALUE(0x00C3FE) forState:UIControlStateNormal];
    [exploreBtn.titleLabel setFont:JSS_FONT_4];
    [exploreBtn addTarget:self action:@selector(exploreBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:exploreBtn];
    [exploreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom).offset(66);
        make.centerX.offset(0);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(20);
    }];
}

 // 连接设备
- (void)addBtnClick
{
    
}

// 去探索
- (void)exploreBtnClick
{
    
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
//    return self.titleArray.count;
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MAddDeviceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MAddDeviceCell"];
    cell.titleLab.text = @"新设备1";
    cell.rightLab.text = @" 已连接 ";
    if (indexPath.row == 9) {
        cell.lineView.hidden = YES;
    } else {
        cell.lineView.hidden = NO;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 55;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
